package com.anbinh.doctor.fragment;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.anbinh.doctor.R;
import com.anbinh.doctor.adapter.MonthAdapter;
import com.anbinh.doctor.model.ItemMeu;
import com.anbinh.doctor.utils.Utils;

public class FragmentMonth extends Fragment {
	private static FragmentMonth fragment = null;
	private View mView;

	public static FragmentMonth newInstance() {
		if (fragment == null) {
			fragment = new FragmentMonth();
		}
		return fragment;
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_message, null);
		return mView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		ListView mGridView = (ListView) mView.findViewById(R.id.listView1);
		mGridView.setDivider(getResources().getDrawable(R.drawable.divider_datlich_ngang));
		mGridView.setDividerHeight(1);
		
		final List<ItemMeu> mList = Utils.getMenu(getActivity(), R.menu.month);
		MonthAdapter adapter = new MonthAdapter(getActivity(),
				R.layout.item_month, mList, 0);
		mGridView.setAdapter(adapter);
		mGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent returnIntent = new Intent();
				returnIntent.putExtra(Utils.TIME, mList.get(position)
						.getTitle());
				Log.d("onItemClick",Activity.RESULT_OK+"");
				getActivity().setResult(Activity.RESULT_OK, returnIntent);
				getActivity().finish();
			}
		});
	}

}
